home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-13
/
me_cd22.zip
/
MC2MUTT.ZIP
/
RANDOM.MUT
< prev
next >
Wrap
Text File
|
1992-04-27
|
866b
|
34 lines
;; Here's a typical (portable) linear-congruential pseudo-random
;; number generator, taken from the draft ANSI C standard; rand() returns an
;; integer uniformly distributed from 0 through 32767 (inclusive), and srand()
;; is used to initialize a sequence to a particular seed, or to avoid getting
;; a predictable sequence (by setting a seed based on some system variable
;; such as process ID or time-of-day).
; static unsigned long int next = 1;
; int rand(void)
; {
; next = next * 1103515245 + 12345;
; return (unsigned int)(next/65536) % 32768;
; }
; void srand(unsigned int seed) { next = seed; }
(include mod.mut)
(int next)
(defun
rand
{
(int x)
(next (+ (* next 1103515245) 12345))
(x (mod (/ next 65536) 32768))
(if (< x 0) (+ x 32767) x)
}
srand (int seed) { (next seed) }
)
;(next 1)